package com.zangyi.controller;

import com.sun.xml.bind.v2.runtime.unmarshaller.IntArrayData;
import com.zangyi.common.Comment;
import com.zangyi.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/comment")
@Api(tags = "评论控制器")
public class CommentController {


    @Autowired
    CommentService commentService;

    //    实体类映射
    @GetMapping("/getComment")
    public Comment getComment() {
        return new Comment();
    }

    //添加用户评论
    @RequestMapping("/addComment")
    @ResponseBody
    public boolean addComment(String username, String title, String comment) {
        return commentService.addComment(username, title, comment);
    }

    //    删除评论
    @RequestMapping("/delComment")
    @ResponseBody
    public void delComment(Integer comId) {
        commentService.delComment(comId);
    }
     //获取某话题下评论
    //参数username为可选参数(即用户登录后传入)，传入时获取评论与用户的关系（是否是自己发的，是否收藏）
    //                map.put("isSelf", 0);0为不是直接发的
     //                map.put("isCol", 0);0为自己没有收藏
     //                map.put("comment", comments.get(i));为当前评论
    @RequestMapping("/getTitleComments")
    @ResponseBody
    public List<Map<String,Object>> getTitleComment(String title, @RequestParam(value = "username",required = false,defaultValue = "null")String username){
        return commentService.getTitleComment(title,username);
    }
//    获取某用户所有评论
    @RequestMapping("/getUserComments")
    @ResponseBody
    public List<Comment> getUserComments(String username){
        return commentService.getUserComments(username);
    }
//    收藏评论
    //传评论id和当前登录的用户名
    @RequestMapping("/collectionComment")
    @ResponseBody
    public boolean collectionComment(Integer comId,String username){
        return commentService.collectionComment(comId,username);
    }
//    取消收藏
    @RequestMapping("/delCollection")
    @ResponseBody
    public void delCollection(Integer colId){
         commentService.delCollection(colId);
    }
//    评论转发
    /*考虑：评论转发后将转发的评论的com_id和转发人（即当前用户）存储在数据库forward表*/
    @RequestMapping("/toForward")
    @ResponseBody
    public void  toForward(Integer comId,String username){
          commentService.toForward(comId,username);
    }
}
